//
//  NSArray+Cool.m
//  CoolFramework
//
//  Created by Felix on 13-3-29.
//  Copyright (c) 2013年 Xue Fei. All rights reserved.
//

#import "NSArray+Cool.h"

@implementation NSArray (Cool)

- (id)objectAtIndex:(NSUInteger)index matchClass:(Class)aClass defaultValue:(id)defaultValue beyondRangeValue:(id)beyondRangeValue {
    if (index >= self.count) {
        return beyondRangeValue;
    }
    id obj = self[index];
    if ([obj isKindOfClass:aClass]) {
        return obj;
    } else {
        return defaultValue;
    }
}

- (id)objectAtIndex:(NSUInteger)index useDescription:(BOOL)useDescription defaultValue:(id)defaultValue beyondRangeValue:(id)beyondRangeValue {
    if (index >= self.count) {
        return beyondRangeValue;
    }
    id obj = self[index];
    if (useDescription) {
        obj = [obj description];
    }
    if (obj) {
        return obj;
    } else {
        return defaultValue;
    }
}

@end
